package com.flink.api.unit3;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * env_1
 *
 * @author caizhiyang
 * @since 2024-02-21
 */
public class env_1 {

    public static void main(String[] args) {
        /**
         * 获取flink执行环境
         */

        //1.通过getExecutionEnvironment()获取
        // 会根据上下文自动获取执行环境.如果在本地执行则创建获取本地运行环境
        // 如果是创建jar包提交集群运行,则返回集群的运行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();


        //2.createLocalEnvironment()获取
        // 创建本地运行环境,可以传入参数指定默认并行度.
        // 如果不传入,则默认并行度为本地CPU的核心数
        StreamExecutionEnvironment env2 = StreamExecutionEnvironment.createLocalEnvironment();


        //3.createRemoteEnvironment()获取
        // 获取集群运行环境,需要指定JobManager的主机名,端口号以及在集群中运行的jar包
        StreamExecutionEnvironment env3 = StreamExecutionEnvironment.createRemoteEnvironment(
                "localhost",        //JobManager的主机名
                1234,                    //JobManager 进程端口号
                "path/to/jarFile.jar" //提交给JobManager的Jar包
        );

    }
}
